
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main() {
    std::vector<int> primes;
    for (int i = 2; i < 1000; i++) {
        int is_prime = 1;
        for (int j = 2; j < i / 2; j++) {
            if (i % j == 0) {
                is_prime = 0;
                break;
            }
        }
        if (is_prime) {
            primes.push_back(i);
        }
    }

    std::vector<std::string> am = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    std::string x;
    std::cin >> x;
    x = x.replace("9", "&").replace("8", "&").replace("7", "&").replace("6", "&")
            .replace("5", "&").replace("4", "&").replace("3", "&").replace("2", "&")
            .replace("1", "&").replace("0", "&");
    
    if (x.find("&") != std::string::npos || x.size() != 3) {
        std::cout << "Wrong input" << std::endl;
    } else {
        std::string y;
        y = x.split();
        std::string new_str = "";
        for (const auto &i : y) {
            new_str += std::to_string(std::distance(am.begin(), std::find(am.begin(), am.end(), i)));
        }
        int gm = std::stoi(new_str);

        std::vector<std::vector<int>> z;
        for (const auto &i : primes) {
            z.push_back({std::abs(gm - i), i});
        }

        std::sort(z.begin(), z.end());
        std::cout << z[0][1] << std::endl;
    }

    return 0;
}
